# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/14 下午6:05
 @Author  : tgy

 需求
  根据字典的value查找最大对应的key
"""


def test01():
    ...
    prices = {'ACME': 45.23, 'AAPL': 612.78, 'IBM': 205.55, 'HPQ': 37.2, 'FB': 10.75}

    print(max(zip(prices.values(), prices.keys())))
    print(sorted(zip(prices.values(), prices.keys())))


def test02():
    ...
    prices = {'ACME': 45.23, 'AAPL': 612.78, 'IBM': 205.55, 'HPQ': 37.2, 'FB': 10.75}
    # x 是迭代对象的值，要获取val排序，只能是 prices[x]
    print(prices[max(prices, key=lambda x: prices[x])])


def test03():
    """
    """
    prices = {'IBM': 21, 'APPLE': 21}
    # 比较(key,val), 如果key相等，则比较val
    print(min(zip(prices.values(), prices.keys())))


if __name__ == '__main__':
    ...
    test03()
